


// let saveAjaxFuciton = $.ajax;
//
//
// $.ajax = function(url,obj ){
//
//     var str = JSON.stringify(obj);
//
//     console.log(str);
//
//     saveAjaxFuciton(url,obj);
// }


window.isInstallLBXHookAjax = true;
window.saveLBXAjaxFuciton = null;

window.LBXHookAjax = function () {

    console.log("LBXHookAjax");

    if (!saveLBXAjaxFuciton){

        window.saveLBXAjaxFuciton = $.ajax;

        console.log("LBXHookAjax");
        $.ajax = function(url,obj ){

            let str = JSON.stringify(obj);
            console.log("ajax " + url + " data:"  + str);
            console.log("ajax hook");

            let saveLBXAjaxSuccess = obj.success;
            let saveLBXAjaxError = obj.error;

            obj.success = function(data){

                let str = null;
                if (data)
                    str = JSON.stringify(data);
                console.log( "ajax hook response: " + str);

                saveLBXAjaxSuccess(data);
            }

            obj.error = function (xhr, type, errorThrown)
            {
                console.log("ajax hook response  error:" + type);
                saveLBXAjaxError(xhr,type,errorThrown);
            }
            saveLBXAjaxFuciton(url,obj);
        }
    }
    return true;
}

window.unLBXHookAjax = function () {

    if (window.saveLBXAjaxFuciton)
    {
        $.ajax = saveLBXAjaxFuciton;
        window.saveLBXAjaxFuciton = null;
    }
    return true;
}

